package com.uniledger.exchange.bank;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uniledger.exchange.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GatewayAdapter extends BaseAdapter {
    List<Gateway> list;
    Context context;

    LayoutInflater inflater;

    public GatewayAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.list = new ArrayList<>();
        this.list.add(new Gateway("ABC Gateway"));
        this.list.add(new Gateway("CBD Gateway"));
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Gateway getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_item_gateway, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Gateway gateway = getItem(position);
        holder.name.setText(gateway.name);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.txt_gateway_name)
        TextView name;
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
